import logging
from logging.handlers import RotatingFileHandler


def register_logger(app, logdir):
    app.logger.setLevel(logging.INFO)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    file_handler = RotatingFileHandler(
        logdir.joinpath('runtime.log'), maxBytes=10 * 1024 * 1024, backupCount=10
    )
    file_handler.setFormatter(formatter)
    file_handler.setLevel(logging.INFO)
    app.logger.addHandler(file_handler)
    app.logger.info('App Startup...')  # 这里额外在日志文件中记录下每次应用服务的启动时间
